package solutions.leetcode.normal

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/problems/partition-array-according-to-given-pivot/">2161. 根据给定数字划分数组</a>
 */
private class Solution2161 {
    fun pivotArray(nums: IntArray, pivot: Int): IntArray {
        val rst = IntArray(nums.size)
        var left = 0
        for (i in nums.indices) {
            if (nums[i] < pivot) {
                rst[left++] = nums[i]
            }
        }
        var right = nums.size - 1
        for (i in nums.indices.reversed()) {
            if (nums[i] > pivot) {
                rst[right--] = nums[i]
            }
        }
        for (i in left .. right) {
            rst[i] = pivot
        }
        return rst
    }
}

fun main() {
    println(Solution2161().pivotArray(arrayOf(
        9,12,5,10,14,3,10
    ).toIntArray(), 10))
}